<template>
  <div>
    <van-nav-bar
      color="#333"
      title="编辑地址"
      left-arrow
      @click-left="onClickLeft"
    />

    <van-address-edit
      :area-list="areaList"
      show-delete
      show-set-default
      show-search-result
      :area-columns-placeholder="['请选择', '请选择', '请选择']"
      @save="onSave"
      @delete="onDelete"
    />
  </div>
</template>
<script>
import { ref } from "vue";
import { Toast } from "vant";
import { areaList } from "@vant/area-data";
import { addAddress } from "../../assets/api/homeapi.js";
export default {
  data() {
    return {
      searchResult: ref([]),
      areaList,
    };
  },
  methods: {
    onClickLeft() {
      history.back();
    },
    onSave(q) {
      let data = {
        addressDetail: q.addressDetail,
        areaCode: q.areaCode,
        city: q.city,
        country: q.country,
        county: q.county,
        isDefault: q.isDefault,
        name: q.name,
        postalCode:q.postalCode,
        province: q.province,
        tel: q.tel,
      };
      addAddress(data, "post").then((r) => {
        this,$this.$router.push("/address")
      });
    },
    onDelete() {
      Toast("delete");
    },

  },
};
</script>
